package demoMod.gdxform.ui;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import demoMod.gdxform.abstracts.Container;
import demoMod.gdxform.core.ActionManager;
import demoMod.gdxform.helpers.FontHelper;
import demoMod.gdxform.interfaces.Element;
import demoMod.gdxform.interfaces.MouseEventSubscriber;

public class GLabel implements Element, MouseEventSubscriber {
    private Container parent;
    private float x;
    private float y;
    private float width;
    private float height;
    private String text;
    private BitmapFont font;
    private boolean enabled = true;
    private Color color = Color.WHITE.cpy();
    private boolean visible = true;
    private String id = "";
    protected ActionManager actionManager;

    public GLabel(float x, float y, float width, float height, BitmapFont font) {
        this(x, y, width, height);
        this.font = font;
    }

    public GLabel(float x, float y, float width, float height) {
        setX(x);
        setY(y);
        setWidth(width);
        setHeight(height);
        actionManager = new ActionManager();
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public void setFont(BitmapFont font) {
        this.font = font;
    }

    public BitmapFont getFont() {
        return this.font;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    @Override
    public void update() {
        actionManager.update();
    }

    @Override
    public void render(SpriteBatch sb) {
        if (this.font == null || !this.visible || this.text == null) return;
        FontHelper.renderSmartText(sb, this.font, this.text, this.getX(true), this.getY(true), this.getWidth(), 0, this.color);
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    @Override
    public Container getParent() {
        return parent;
    }

    @Override
    public void setParent(Container parent) {
        this.parent = parent;
    }

    public float getX(boolean isAbsolute) {
        return isAbsolute && getParent() != null ? getParent().getX(true) + x : x;
    }

    @Override
    public float getY(boolean isAbsolute) {
        return isAbsolute && getParent() != null ? getParent().getY(true) + y : y;
    }

    @Override
    public void setX(float x) {
        this.x = x;
    }

    @Override
    public void setY(float y) {
        this.y = y;
    }

    @Override
    public float getWidth() {
        return this.width;
    }

    @Override
    public float getHeight() {
        return this.height;
    }

    @Override
    public void setWidth(float width) {
        this.width = width;
    }

    @Override
    public void setHeight(float height) {
        this.height = height;
    }

    @Override
    public Color getBackground() {
        return null;
    }

    @Override
    public void setBackground(Color background) {

    }

    @Override
    public boolean isResizable() {
        return false;
    }

    @Override
    public void setResizable(boolean resizable) {

    }

    @Override
    public boolean enabled() {
        return this.enabled;
    }

    @Override
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    @Override
    public void dispose() {
    }

    @Override
    public boolean clickDown(int screenX, int screenY, int button) {
        return false;
    }

    @Override
    public boolean clickUp(int screenX, int screenY, int button) {
        return false;
    }

    @Override
    public boolean mouseDragged(int screenX, int screenY) {
        return false;
    }

    @Override
    public boolean mouseMoved(int screenX, int screenY) {
        return false;
    }

    @Override
    public boolean scrolled(int amount) {
        return false;
    }

    @Override
    public boolean moveToElementBorder(Element element) {
        return false;
    }

    @Override
    public boolean visible() {
        return visible;
    }

    @Override
    public void setVisible(boolean visible) {
        this.visible = visible;
    }
}
